package com.resttest.ljs.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;


@Controller
@Slf4j
public class ProController {

    @Value("${api.url}")
    private String url;

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/index/{name}")
    @ResponseBody
    public String index(@PathVariable String name){
        JSONObject object=new JSONObject();
        object.put("name",name);
        object.put("age","12");
        log.info("接收页面报文{}",object.toJSONString());
        String result= restTemplate.postForObject("http://localhost:8090/jieshou?xtdm="+"ceshi",object,String.class);
        return result;
    }
}
